package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.XcDeptDao;
import com.qfedu.stussm.entity.Dept;
import com.qfedu.stussm.entity.XcDept;
import com.qfedu.stussm.service.intf.XcDeptService;
import com.qfedu.stussm.vo.DeptR;
import com.qfedu.stussm.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service

public class XcDeptServiceImpl implements XcDeptService {
    @Autowired
    private XcDeptDao xcDeptDao;
    @Override
    public DeptR insert(XcDept xcDept) {
        System.out.println(xcDept);
        if(xcDeptDao.insert(xcDept)>0){
            return DeptR.ok();
        }else{
            return DeptR.fail();
        }
    }
    @Override
    public PageBeanVo select(String xcdept_name,int page, int limit) {
        PageHelper.startPage(page,limit);
        if(xcdept_name!=null && xcdept_name.length()>0){
            xcdept_name="%"+xcdept_name+"%";
            System.out.println(xcdept_name);
        }else{
            xcdept_name=null;
        }
        PageInfo<Dept> pageInfo = new PageInfo<>(xcDeptDao.select(xcdept_name));
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public DeptR del(Integer id) {
        if(xcDeptDao.del(id)>0){
            return DeptR.ok();
        }else{
            return  DeptR.fail();
        }
    }

    @Override
    public DeptR update(XcDept xcDept) {
        if(xcDeptDao.update(xcDept)>0){
            return DeptR.ok();
        }else{
            return  DeptR.fail();
        }
    }
    @Override
    public DeptR dele(Integer[] ids) {
        if(xcDeptDao.dele(ids)>0){
            return DeptR.ok();
        }else{
            return DeptR.fail();
        }
    }
}
